asList

fun <E> Expect<Array<E>>.asList(assertionCreator: Expect<List<E>>.() -> Unit): Expect<Array<E>>(source)(source)

Expects that the subject of this expectation holds all assertions the given assertionCreator creates for the subject as List.

The transformation as such is not reflected in reporting. Use feature(Array<out E>::asList, assertionCreator) if you want to show the transformation in reporting.

Return

The newly created Expect for the transformed subject.

Since

0.9.0

Samples

expect(arrayOf("A", "B"))
    .asList { // subject within this expectation-group is of type List<String>
        toEqual(listOf("A", "B"))
    } // subject here is back to type Array<String>

fails {
    // all expectations inside an expectation-group are evaluated together; for more details see:
    // https://github.com/robstoll/atrium#define-single-expectations-or-an-expectation-group

    expect(arrayOf("A", "B"))
        .asList {
            toContain("C")  // fails
            toContain("D")  // still evaluated even though above `toContain` already fails
            //                 use `.asList().` if you want a fail fast behaviour
        }
}

@JvmName(name = "asListEOut")
fun <E> Expect<Array<out E>>.asList(assertionCreator: Expect<List<E>>.() -> Unit): Expect<Array<out E>>(source)(source)

Expects that the subject of this expectation holds all assertions the given assertionCreator creates for the subject as List.

The transformation as such is not reflected in reporting. Use feature(Array<out E>::asList, assertionCreator) if you want to show the transformation in reporting.

Return

The newly created Expect for the transformed subject.

Since

0.9.0

Samples

expect<Array<out String>>(arrayOf("A", "B"))
    .asList { // subject within this expectation-group is of type List<String>
        toEqual(listOf("A", "B"))
    } // subject here is back to type Array<out String>

fails {
    // all expectations inside an expectation-group are evaluated together; for more details see:
    // https://github.com/robstoll/atrium#define-single-expectations-or-an-expectation-group

    expect<Array<out String>>(arrayOf("A", "B"))
        .asList {
            toContain("C")  // fails
            toContain("D")  // still evaluated even though above `toContain` already fails
            //                 use `.asList().` if you want a fail fast behaviour
        }
}